package com.jingdianjichi.subject.common.entity;

import lombok.Data;
import lombok.Setter;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * PageResponse 类
 *
 * @author 熊苏鹏1
 * @date 2025/2/21 17:13
 * @description 分页响应封装
 */
@Data
public class PageResponse <T> implements Serializable {
    private Integer pageNum = 1;
    private Integer pageSize = 10;
    private Integer total;
    private Integer totalPage;
    private List<T> result = Collections.emptyList();

    private Integer start;

    public void setResult(List<T> result) {
        this.result = result;
        if (result != null) {
            setTotal(result.size());
        }
    }
    public void setTotal(Integer total){
        this.total = total;
        this.totalPage =  total/pageSize + (total%pageSize == 0 ? 0 : 1);;

    }



    public void setStart(Integer start) {
        this.start = start;
    }

    public Integer getPageNum() {
        return pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public Integer getTotal() {
        return total;
    }

    public List<T> getResult() {
        return result;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }
    public Integer getStart() {
        this.start = (pageNum - 1) * pageSize;
        return this.start;
    }
}
